package com.lck.blogmanager.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lck.blogmanager.common.Response;
import com.lck.blogmanager.entity.TagEntity;
import com.lck.blogmanager.req.AuditQuestionReq;
import com.lck.blogmanager.req.PageQuestionReq;
import com.lck.blogmanager.req.UserQuestionListReq;
import com.lck.blogmanager.res.*;
import com.lck.blogmanager.service.QuestionService;
import com.lck.blogmanager.service.TagService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 问答
 * @author wyq
 * @version v1.0.0
 * @explain
 * @date 2024/4/7 18:29
 */

@RequestMapping("/question")
@RequiredArgsConstructor
@Slf4j
@RestController
@CrossOrigin
public class QuestionController {

    private final QuestionService questionService;
    private final TagService tagService;



    /**
     * 用户问答列表
     * @param req
     * @return
     */
    @PostMapping("/userList")
    public Response<Page<UserQuestionListRes>> userList(@RequestBody UserQuestionListReq req){
        Page<UserQuestionListRes> page = questionService.userList(req);
        return Response.success(page);
    }

    /**
     * 用户端问答详情
     * @param questionId
     * @return
     */
    @GetMapping("/userDetail/{questionId}")
    public Response<QuestionUserDetailRes> userDetail(@PathVariable Integer questionId){
        QuestionUserDetailRes res = questionService.userDetail(questionId);
        return Response.success(res);
    }


    /**
     * 获取所有标签
     * @return
     */
    @GetMapping("/getTag")
    public Response<List<TagEntity>> getTag(){
        List<TagEntity> list = tagService.getQuestionTag();
        return Response.success(list);
    }


    /**
     * ---------------------------管理端
     */


    /**
     * 管理端问答列表
     * @param req
     * @return
     */
    @PostMapping("/page")
    public Response<Page<PageQuestionRes>> pageQuestion(@RequestBody PageQuestionReq req){
        Page<PageQuestionRes> page = questionService.pageQuestion(req);
        return Response.success(page);
    }

    /**
     * 问答详情
     * @param questionId
     * @return
     */
    @GetMapping("/detail/{questionId}")
    public Response<DetailQuestionRes> detailQuestion(@PathVariable Integer questionId){
        DetailQuestionRes res = questionService.detailQuestion(questionId);
        return Response.success(res);
    }

    /**
     * 审核
     * @param req
     * @return
     */
    @PostMapping("/audit")
    public Response auditQuestion(@RequestBody AuditQuestionReq req){
        questionService.auditQuestion(req);
        return Response.success();
    }


    /**
     * 点赞
     * @return
     */
    @GetMapping("/like")
    public Response likeQuestion(Integer questionId){
        questionService.likeQuestion(questionId);
        return Response.success();
    }

    /**
     * 收藏
     * @return
     */
    @PostMapping("/collect")
    public Response collectQuestion(Integer questionId){
        questionService.collectQuestion(questionId);
        return Response.success();
    }

}
